package cn.mxz.generator.config;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

import lincen.javase.util.Closer;

public class FileUtilImpl implements FileUtil {

	private File file;

	/**
	 * @param filePath	文件路径
	 */
	public FileUtilImpl(String filePath) {
		this.file = new File(filePath);
		if(!file.getParentFile().exists()) {
			file.getParentFile().mkdirs();
		}
	}

	@Override
	public void writeToFile(String content) {
		OutputStreamWriter ow = null;
		
		try {
			
			if(!file.exists()) {
				file.createNewFile();
			}
			ow = new OutputStreamWriter(new FileOutputStream(file), "utf8");
			ow.write(content);
			ow.flush();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			Closer.close(ow);
		}
	}

}
